{include file="public/header" /}



<div class="page">

    <div class="fixed-empty"></div>
    <form id="link_form" enctype="multipart/form-data" method="post">
        <table class="ds-default-table">
            <tbody>
            <tr class="noborder">
                <td class="required w120"><label class="validation" for="ap_name">广告类型名称:</label></td>
                <td class="vatop rowform">
                    <select name="ap_name" id="ap_name">
                        <option value='1' {if condition="$ap.ap_name == 1"}selected{/if}>视频广告</option>
                        <option value='2' {if condition="$ap.ap_name == 2"}selected{/if}>商品促销</option>
                        <option value='3' {if condition="$ap.ap_name == 3"}selected{/if}>项目定制</option>
                        <option value='4' {if condition="$ap.ap_name == 4"}selected{/if}>文章类</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 添加视频-->
{if $ap.ap_name == 1}
            <tr class="noborder" id="video_type">
                <td class="w120 required">视频:</td>
                <td class="vatop rowform">
                        <video width="300" height="300" controls>
                           <source src="{$http_name}/{$ap.videos}" type="video/mp4">
                        </video>
                    <div class="goodspic-uplaod">
                        <span></span>
                        <input type="hidden" name="videos" id="video_name"
                        />
                        <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Adv/ajax_videos')}">
                        </span>
                        <p class="hint"></p>
                    </div>
                </td>
            </tr>
{/if}
            <!-- 打折 促销-->

{if $ap.ap_name == 2}
            <tr class="noborder" style="" id="goods_type">
                <td class="w120 required">商品分类:</td>
                <td class="vatop rowform">
                    <select name="goods_type" >
                        <option value='1' {if condition="$ap.goods_type == 1"}selected{/if}>打折</option>
                        <option value='2' {if condition="$ap.goods_type == 2"}selected{/if}>促销</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
{/if}
{if $ap.ap_name == 3}
            <!-- 项目定制 -->
            <tr class="noborder" style="" id="project_type">
                <td class="required w120">项目定制标题:</td>
                <td class="vatop rowform">
                    <select name="project_type">
                        {foreach name="project_title" item="v" key="ap_k" }
                        <option value='{$v.project_id}' {if condition="$ap.project_type == $v.project_id"}selected{/if}>{$v.project_title}</option>
                        {/foreach}
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
{/if}
{if $ap.ap_name == 4}
            <!--                文章-->
            <tr class="noborder" style="" id="artice_type">
                <td class="required w120">文章:</td>
                <td class="vatop rowform">
                    <select name="article_type">
                        {foreach name="article_info" item="v" key="ap_k" }
                        <option value='{$v.article_id}' {if condition="$ap.article_type == $v.article_id"}selected{/if}>{$v.article_title}</option>
                        {/foreach}
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
{/if}
            <tr class="noborder">
                <td class="required">{$Think.lang.ap_isuse}:</td>
                <td class="vatop rowform">
                    <div class="onoff">
                        <label for="ap_isuse1" class="cb-enable {if condition="$ap.ap_isuse eq 1"}selected{/if}">{$Think.lang.ap_use_s}</label>
                        <label for="ap_isuse0" class="cb-disable {if condition="$ap.ap_isuse eq 0"}selected{/if}">{$Think.lang.ap_not_use_s}</label>
                        <input id="ap_isuse1" name="ap_isuse" value="1" type="radio" {if condition="$ap.ap_isuse eq 1"} checked="checked"{/if} />
                        <input id="ap_isuse0" name="ap_isuse" value="0" type="radio" {if condition="$ap.ap_isuse eq 0"} checked="checked"{/if} />
                    </div>
                </td>
                <td class="vatop tips"></td>
            </tr>

            <!--                <tr class="noborder">-->
            <!--                    <td class="required"><label class="validation" for="ap_width">{$Think.lang.ap_width}:</label></td>-->
            <!--                    <td class="vatop rowform"><input type="text" name="ap_width" class="txt" id="ap_width" value="{$ap.ap_width|default=''}"></td>-->
            <!--                    <td class="vatop tips">{$Think.lang.adv_pix}</td>-->
            <!--                </tr>-->
            <!--                <tr class="noborder">-->
            <!--                    <td class="required"><label class="validation" for="ap_height">{$Think.lang.ap_height}:</label></td>-->
            <!--                    <td class="vatop rowform"><input type="text" name="ap_height" class="txt" id="ap_height" value="{$ap.ap_height|default=''}"></td>-->
            <!--                    <td class="vatop tips">{$Think.lang.adv_pix}</td>-->
            <!--                </tr>-->
            </tbody>
            <tfoot>
            <tr class="tfoot" style="text-align: center;">
                <td colspan="15" ><input class="btn" type="submit" value="{$Think.lang.ds_submit}"/></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/layui/layui.js"></script>
<script>
    $(document).ready(function () {
        var type = $('#ap_name option:selected').val();
        // if(type == 1){
        //     $("#video_type").show();
        //     $("#goods_type").hide();
        //     $("#project_type").hide();
        //     $("#artice_type").hide();
        // }else if(type == 2){
        //     $("#goods_type").show();
        //     $("#video_type").hide();
        //     $("#project_type").hide();
        //     $("#artice_type").hide();
        // }else if(type == 3){
        //     $("#project_type").show();
        //     $("#goods_type").hide();
        //     $("#video_type").hide();
        //     $("#artice_type").hide();
        // }else{
        //     $("#artice_type").show();
        //     $("#project_type").hide();
        //     $("#goods_type").hide();
        //     $("#video_type").hide();
        // }
        $('#link_form').validate({
            errorPlacement: function (error, element) {
                error.appendTo(element.parent().parent().find('td:last'));
            },
            rules: {

                ap_width: {
                    required: true
                },
                ap_height: {
                    required: true
                },
            },
            messages: {

                ap_width: {
                    required: '{$Think.lang.ap_input_digits_pixel}',
                },
                ap_height: {
                    required: '{$Think.lang.ap_input_digits_pixel}',
                },
            }
        });
    });




    //按钮先执行验证再提交表单
    $(function() {
        $('#type_div').perfectScrollbar();
        $("#pic").change(function() {
            $("#textfield1").val($(this).val());
        });
        $('input[type="radio"][name="cat_id"]').click(function() {
            if ($(this).val() == '0') {
                $('#t_name').val('');
            } else {
                $('#t_name').val($(this).next('span').html());
            }
        });
        // 所属分类
        $(document).off('change',"#gc_parent_id").on("change","#gc_parent_id", function() {
            type_scroll($(this));
        });
        // 类型搜索
        $(document).off('change',"#gcategory > select").on("change","#gcategory > select", function() {
            type_scroll($(this));
        });
        $(document).on('change', '#videos', function () {

            $('#dataLoading').show();
            var files = document.getElementById('videos').files[0];
            var formData = new FormData();
            var obj = $(this);
            formData.append('file', files);
            var url = $(this).attr('data-action');
            $.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: url,
                data: formData,
                cache: false,  //默认是true，但是一般不做缓存
                processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                //请求成功
                success: function (result) {
                    if (result.msg == 1) {
                        $('.vide').empty();
                        $('#dataLoading').hide();
                        layer.msg('上传成功');
                        $("#video_name").val(result.files_name);
                        // $("type[name='old_filename']").val(result.old_name);
                    } else {
                        obj.val('');
                        $('#dataLoading').hide();
                        layer.msg('文件信息错误,请重新上传');
                        return false;
                    }

                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });

        });

        $('#ap_name').change(function(){
            var type = $(this).children('option:selected').val();//这就是selected的值
            if(type == 1){
                $("#video_type").show();
                $("#goods_type").hide();
                $("#project_type").hide();
                $("#artice_type").hide();
            }else if(type == 2){
                $("#goods_type").show();
                $("#video_type").hide();
                $("#project_type").hide();
                $("#artice_type").hide();
            }else if(type == 3){
                $("#project_type").show();
                $("#goods_type").hide();
                $("#video_type").hide();
                $("#artice_type").hide();
            }else{
                $("#artice_type").show();
                $("#project_type").hide();
                $("#goods_type").hide();
                $("#video_type").hide();
            }

        });


    });

    var typeScroll = 0;
    function type_scroll(o) {
        var id = o.val();
        if (!$('#type_dt_' + id).is('dt')) {
            return false;
        }
        $('#type_div').scrollTop(-typeScroll);
        var sp_top = $('#type_dt_' + id).offset().top;
        var div_top = $('#type_div').offset().top;
        $('#type_div').scrollTop(sp_top - div_top);
        typeScroll = sp_top - div_top;
    }
    gcategoryInit('gcategory');


</script>